package com.calsoft.Hops_Mobile_Tablet;

import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.*;
import com.calsoft.Hops_Mobile_Tablet.base.App;
import com.calsoft.Hops_Mobile_Tablet.base.CountriesList;
import com.calsoft.Hops_Mobile_Tablet.base.SimpleListArrayAdapter;
import com.calsoft.Hops_Mobile_Tablet.component.AlertDialogFragment;
import com.calsoft.Hops_Mobile_Tablet.sql.LocationDbAdapter;
import com.calsoft.Hops_Mobile_Tablet.util.SharedPrefs;

import java.util.ArrayList;
import java.util.Collections;


/*
 * User: Minh Diep
 * Date: 6/24/13
 * Time: 5:59 PM
 */

public class SubLocationActivity extends FragmentActivity {

    private SharedPrefs sPrefs;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sublocation);

        ListView listView = (ListView) findViewById(R.id.sublocation_listview);
        EditText inputFilter = (EditText) findViewById(R.id.sublocation_filter);

        sPrefs = new SharedPrefs(getApplicationContext());

        final ArrayList<String> list = new ArrayList<String>();
        Collections.addAll(list, CountriesList.name);

        final SimpleListArrayAdapter adapter = new SimpleListArrayAdapter(this,
                android.R.layout.simple_list_item_1, list);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, final View view,
                                    int position, long id) {
                String countryName = (String) parent.getItemAtPosition(position);
                sPrefs.putString(SharedPrefs.CURRENT_COUNTRY, countryName);
                finish();
            }

        });

        inputFilter.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                adapter.getFilter().filter(s);
            }

            @Override
            public void afterTextChanged(Editable s) {
            }
        });


    }

    @Override
    protected void onStop() {
        super.onStop();

    }

}